# Maintainer: Jelle van der Waa <jelle@archlinux.org>
# Maintainer: Bruno Pagani <archange@archlinux.org>
# Contributor: Platon Pronko <platon7pronko@gmail.com>

pkgname=python-lsp-server
pkgver=1.8.0
pkgrel=1
pkgdesc="Fork of the python-language-server project, maintained by the Spyder IDE team and the community"
arch=(any)
url="https://github.com/python-lsp/python-lsp-server"
license=(MIT)
depends=(python-jedi python-lsp-jsonrpc python-pluggy python-ujson python-setuptools python-websockets python-docstring-to-markdown)
makedepends=(python-build python-installer python-setuptools-scm python-wheel)
optdepends=(
    'python-mccabe: complexity checking'
    'python-pycodestyle: linter - style checking'
    'python-pydocstyle: linter - docstring style checking'
    'python-pyflakes: linter to detect various errors'
    'python-pylint: code linting'
    'python-rope: for completions and renaming'
    'autopep8: code formatting'
    'flake8: error checking'
    'yapf: code formatting (preferred)'
    'python-whatthepatch: required for yapf support'
)
checkdepends=(
    python-pytest
    python-flaky
    python-mccabe
    python-pycodestyle
    python-pydocstyle
    python-pyflakes
    python-pylint
    python-rope
    autopep8
    flake8
    yapf
    python-whatthepatch
    python-matplotlib
    python-numpy
    python-pandas
    python-pyqt5
    python-appdirs
)
source=(https://files.pythonhosted.org/packages/source/${pkgname::1}/${pkgname}/${pkgname}-${pkgver}.tar.gz)
sha256sums=('807b0347cf83f02cbd9113a68624ac5dbf8b01854a3b11dd03c3bbbdff4e5d89')

prepare() {
  cd ${pkgname}-${pkgver}
  sed 's|jedi>=0.17.2,<0.19.0|jedi>=0.17.2,<0.20.0|' -i pyproject.toml
  sed 's|autopep8>=1.6.0,<1.7.0|autopep8>=1.6.0|' -i pyproject.toml
  sed 's|flake8>=6.1.0,<7|flake8>=6.1.0|' -i pyproject.toml
  sed 's|mccabe>=0.7.0,<0.8.0|mccabe>=0.7.0|' -i pyproject.toml
  sed 's|pycodestyle>=2.11.0,<2.12.0|pycodestyle>=2.11.0|' -i pyproject.toml
  sed 's|pyflakes>=3.1.0,<3.2.0|pyflakes>=3.1.0|' -i pyproject.toml
  sed 's|yapf<=0.32.0|yapf>=0.33.0|' -i pyproject.toml
}

build() {
  cd ${pkgname}-${pkgver}
  python -m build -wn
}

check() {
  cd ${pkgname}-${pkgver}
  # Disable coverage
  sed -i '/--cov/d' pyproject.toml
  pytest -vv --color=yes
}

package() {
  cd ${pkgname}-${pkgver}
  python -m installer -d="${pkgdir}" dist/*.whl
  install -Dm644 LICENSE -t "${pkgdir}"/usr/share/licenses/${pkgname}/
}
